package com.example.demo.mapper;

import com.example.demo.model.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.boot.convert.DataSizeUnit;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Select("select * from user_Info")
    List<UserInfo> selectAll();
    @Select("select * from user_info where id=3 or id=4")
    List<UserInfo> selectByTwoID();

    @Select("select * from user_info where id=#{id} ")
    List<UserInfo> selectById(Integer id);

    @Select("select * from user_info where id=#{ID} ")
    UserInfo selectById1( @Param("ID")Integer id);

    @Select("select * from user_info where id=#{user.id}")
    List<UserInfo> selectById2(@Param("user") UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info(username,password,age) values(#{username},#{password},#{age})")
    Integer insert(UserInfo userInfo);

    @Insert("insert into user_info(username,password,age) values(#{username},#{password},#{age})")
    Integer insert2(String username,String password,Integer age);

    @Delete("delete from user_info where id=#{id}")
    Integer deleteById(Integer id);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Update("update user_info set username=#{username},password=#{password} where username=#{username}")
    Integer updateById(UserInfo userInfo);

    @Select("select id, username, `password`, age, gender, phone, delete_flag as " +
            " deleteFlag,create_time as createTime, update_time as updateTime from user_info")
    List<UserInfo> selectAllAndAnotherName1();


    @Results(value = {@Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")},id = "map")
    @Select("select * from user_info")
    List<UserInfo> selectAllAndAnotherName2();


    @ResultMap("map")
    @Select("select * from user_info where id=#{id}")
    List<UserInfo> selectAllAndAnotherName3(UserInfo userInfo);
}
